EbN0_db_set = 0:8;
load(SCICOM+"\demos\QPSK\QPSK_GrayCode_Simulation.cos");
global errBitNum
totalBitNum = 1D+5;
tf = totalBitNum / 2;
BER = zeros(EbN0_db_set);

for i = 1:length(EbN0_db_set)
  EbN0_db = EbN0_db_set(i);
  %scicos_context.EbN0_db = EbN0_db;
  disp("simulating SNR: "+string(EbN0_db)+" dB");
  scs_m.props.tf = tf;
  scicos_simulate(scs_m, list(), %scicos_context);
  BER(i) = errBitNum/totalBitNum;
end
validPos = find(BER > 0);
plot(EbN0_db_set(validPos), log10(BER(validPos)), '*')

//theoretical BER
EbN0_db = 0:0.1:10;
EbN0 = 10^(EbN0_db/10);
theoryBER = 0.5*erfc(sqrt(EbN0));
plot(EbN0_db, log10(theoryBER))
